package com.sn.test;

import java.util.List;

import com.sn.bean.Student;
import com.sn.utils.BeanHander;
import com.sn.utils.BeanListHander;
import com.sn.utils.JdbcTemplate;

public class StudentDemo {

	
	/*public Student get(Long id){
		String sql = "select * from t_student where id = ?";
		StudentResultSetHandler rsh = new StudentResultSetHandler();
		List<Student> students = JdbcTemplate.query(sql, rsh, id);
		return students.get(0);
	}*/
	
	
	public Student get(Long id){
		String sql = "select * from t_student where id = ?";
		BeanHander<Student> benBeanHander = new BeanHander<>(Student.class);
		Student suStudent = JdbcTemplate.query(sql, benBeanHander, id);
		return suStudent;
	}
	
	public List<Student> getlist() {
		String sql = "select * from t_student";
		BeanListHander<Student> rsh = new BeanListHander<>(Student.class);
		List<Student> list = JdbcTemplate.query(sql, rsh);
		return list;
	}
	
	
	
	public int save(Student student) {
		String sql = "INSERT into t_student (age,name) VALUES (?, ?)";
		Object[] params = {student.getAge(), student.getName()};
		return JdbcTemplate.update(sql, params);
	}
	
	
	public int delete(Long id) {
		String sql = "delete from t_student where id = ?";
		return JdbcTemplate.update(sql, id);
	}
	
	public int update(Student student) {
		String sql = "update t_student set name = ?, age = ? where id = ?";
		Object[] params = {student.getName(), student.getAge(), student.getId()};
		return JdbcTemplate.update(sql, params);
	}
	
	
	
	
	
	
	
	
	
}
